package com.nbjtjc.safe.service.safe;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.safe.SafeBasisClassifyMapper;
import com.nbjtjc.safe.mapper.safe.SafeBasisMapper;
import com.nbjtjc.safe.model.safe.RiskPoint;
import com.nbjtjc.safe.model.safe.SafeBasis;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SafeBasisServiceImpl {

    @Autowired
    private SafeBasisMapper basisMapper;

    @Autowired
    private SafeBasisClassifyMapper safeBasisClassifyMapper;

    public Result search(SafeBasis basis){
        Result result=new Result();
        getCCode(basis);
        if(StringUtils.isEmpty(basis.getKeyword())){
            basis.setKeyword(null);
        }
        PageHelper.startPage(basis.getPageCurrent(),basis.getPageSize());
        List<SafeBasis> safeBasisList= basisMapper.search(basis);
        result.setData(new PageInfo<>(safeBasisList));
        return result;
    }
    /**
     * dCode 风险点的分类，有上下级，获取当前级下面的所有风险点的dCOde
     */
    public void getCCode(SafeBasis safeBasis){
        if(StringUtils.isNotEmpty(safeBasis.getPid())){
            List<String> dCodeList=safeBasisClassifyMapper.findByPid(safeBasis.getPid(),0);
            safeBasis.getCodeList().addAll(dCodeList);
        }
        if(StringUtils.isNotEmpty(safeBasis.getCCode())){
            safeBasis.getCodeList().add(safeBasis.getCCode());
        }
    }
    public Result update(){
        Result result=new Result();

        return result;
    }

    public Result delete(){
        Result result=new Result();

        return result;
    }
}
